﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPMS.Utility;

namespace SPMS.Log.ObjectFormatter
{
    /// <summary>
    /// 抽象对象格式化器
    /// </summary>
    /// <remarks>提供了对象格式化器的基类实现</remarks>
    /// <history>
    /// [zanezeng]               2010/1/13 13:15    创建
    /// </history>
    public abstract class AbstractObjectFormatter : IObjectFormatter
    {
        #region ---IObjectFormatter

        /// <summary>
        /// 将指定的对象格式化为字符串
        /// </summary>
        /// <param name="provider">对象格式化器提供者</param>
        /// <param name="obj">要格式化的对象</param>
        /// <returns>给定对象的字符串描述信息</returns>
        /// <remarks></remarks>
        /// <exception cref="ArgumentNullException"><paramref name="provider"/>为<c>null</c>引用。</exception>
        /// <history>
        /// [zanezeng]               2009/9/29 11:49    创建
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2010/1/13 13:18    创建
        /// </history>
        public string Format( IObjectFormatterProvider provider, object obj )
        {
            //断言参数
            ArgumentAssert.AssertArgumentNotNull( provider, "provider" );

            //转调
            return this.FormatObject( provider, obj, null, null );
        }

        /// <summary>
        /// 将指定的对象格式化为字符串
        /// </summary>
        /// <param name="provider">对象格式化器提供者</param>
        /// <param name="obj">要格式化的对象</param>
        /// <param name="format">对象的格式化字符串</param>
        /// <returns>给定对象的字符串描述信息</returns>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/20 10:57    创建
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2010/1/13 13:15    创建
        /// </history>
        public string Format( IObjectFormatterProvider provider, object obj, string format )
        {
            //断言参数
            ArgumentAssert.AssertArgumentNotNull( provider, "provider" );

            //转调
            return this.FormatObject( provider, obj, format, null );
        }

        /// <summary>
        /// 将指定的对象格式化为字符串
        /// </summary>
        /// <param name="provider">对象格式化器提供者</param>
        /// <param name="obj">要格式化的对象</param>
        /// <param name="formatProvider">格式化提供者，提供用于检索控制格式化的对象的机制</param>
        /// <returns>给定对象的字符串描述信息</returns>
        /// <remarks></remarks>
        /// <exception cref="ArgumentNullException"><paramref name="provider"/>为<c>null</c>引用。</exception>
        /// <history>
        /// [zanezeng]               2009/10/20 10:57    创建
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2010/1/13 15:29    创建
        /// </history>
        public string Format( IObjectFormatterProvider provider, object obj, IFormatProvider formatProvider )
        {
            //断言参数
            ArgumentAssert.AssertArgumentNotNull( provider, "provider" );

            //转调
            return this.FormatObject( provider, obj, null, formatProvider );
        }

        /// <summary>
        /// 将指定的对象格式化为字符串
        /// </summary>
        /// <param name="provider">对象格式化器提供者</param>
        /// <param name="obj">要格式化的对象</param>
        /// <param name="format">对象的格式化字符串</param>
        /// <param name="formatProvider">格式化提供者，提供用于检索控制格式化的对象的机制</param>
        /// <returns>给定对象的字符串描述信息</returns>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/20 10:57    创建
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2010/1/13 13:15    创建
        /// </history>
        public string Format( IObjectFormatterProvider provider, object obj, string format, IFormatProvider formatProvider )
        {
            //断言参数
            ArgumentAssert.AssertArgumentNotNull( provider, "provider" );

            //转调
            return this.FormatObject( provider, obj, format, formatProvider );
        }

        #endregion

        #region ---Protected Method

        /// <summary>
        /// 将指定的对象格式化为字符串
        /// </summary>
        /// <param name="provider">对象格式化器提供者</param>
        /// <param name="obj">要格式化的对象</param>
        /// <param name="format">对象的格式化字符串</param>
        /// <param name="formatProvider">格式化提供者，提供用于检索控制格式化的对象的机制</param>
        /// <returns>给定对象的字符串描述信息</returns>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2010/1/13 13:19    创建
        /// </history>
        protected abstract string FormatObject( IObjectFormatterProvider provider, object obj, string format, IFormatProvider formatProvider );

        #endregion
    }
}
